<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-tabs>
        <el-tab-pane label="用户管理" name="first">
          <el-form
            ref="fromRef"
            :model="from"
            :rules="rules"
            label-width="100px"
            style="width: 350px; margin-left: 300px"
          >
            <el-form-item label="姓名" prop="username">
              <el-input v-model="from.username" />
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="from.password" />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                size="small"
                @click="submit"
              >更新</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
          <UserInfo />
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">
          <JobInfo />
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import { getEmplyeeBaseInfo } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
import JobInfo from './components/job-info.vue'
import UserInfo from './components/user-info.vue'
export default {
  name: 'Detail',
  components: { JobInfo, UserInfo },
  props: {
    id: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      from: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  async created() {
    this.from = await getEmplyeeBaseInfo(this.$route.params.id)
    this.from.password = ''
  },
  methods: {
    submit() {
      this.$refs.fromRef.validate(async(isOk) => {
        if (!isOk) {
          return
        }
        await saveUserDetailById(this.from)
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
